from django.shortcuts import render
from django.db.models import Q
from search.models import Drug

def search(request):
    query = request.GET.get('query', '')
    search_results = []
    
    if query:
        search_results = Drug.objects.filter(
            Q(name__icontains=query) |
            Q(formula__icontains=query) |
            Q(structure__icontains=query)
        ).order_by('-name')
        
    return render(request, 'search/results.html', {
        'search_results': search_results,
        'query': query
    }) 